package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderDetailVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    //插入订单
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    //根据订单id查询订单
    @Select("select * from orders where id = #{id}")
    Orders getById(String id);

    //分页查询
    Page<OrderDetailVO> PageQuerySelect(OrdersPageQueryDTO ordersPageQueryDTO);


    //待派送
    @Select("select count(status) AS confirmed from orders where status=3")
    Integer getConfirmed();
    //派送中
    @Select("select count(status) AS confirmed from orders where status=4")
    Integer getDeliveryInProgress();
    //待接单
    @Select("select count(status) AS confirmed from orders where status=2")
    Integer getToBeConfirmed();

    //分页查询
    Page<OrderDetailVO> PageAdminOrder(OrdersPageQueryDTO ordersPageQueryDTO);

    //查询超时订单
    @Select("select * from orders where status=#{status} and order_time<#{time}")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime time);

    //查询派送中的订单
    @Select("select * from orders where status=#{status}")
    List<Orders> getByDeliveryOrder(Integer status);

    //全部订单数量
    @Select("select count(id) from orders")
    Integer getAllOrder();

    //已取消数量
    @Select("select count(id) from orders where status = 6")
    Integer getCancelOrder();

    //已完成数量
    @Select("select count(id) from orders where status = 5")
    Integer getCompletedOrders();

}

